<?php
/**
 * Project: firework-cms             >>  http://firework-cms.googlecode.com
 * Authors: YouniS Ben Salah  (-.-)  >>  http://younishd.kegtux.org
 *          Fabien Wang       (^.^)  >>  http://fabienwang.fr
 * License: See README and LICENSE in the top level directory
 */
 
/**
 * Module: View [V]
 * Handles all types of output, requests data from Model
 * and generates the html5/css3 code ( getting code snippets from a template system ).
 */
 
require_once 'core/cl_config.php';
require_once 'core/cl_model.php';
require_once 'core/cl_template.php';

/**
 * Class: View
 * represents the [V] module.
 */
class View
{
    // ctor
    public function __construct( $unit = '' )
    {
        $data = array();
        $this->unit = $unit;
        $this->template_system = new TemplateSystem();
    }
    
    /**
     * Method: genCode()
     * returns complete and constant html5/css3 code of a unit.
     */
    public function genCode()
    {
        // check if required unit exists.
        if ( file_exists( 'units'.DS.$this->unit.'.php' ) ) {
            require 'units'.DS.$this->unit.'.php';
        }
        else {
            require 'units'.DS.'default.php';
        }
        // evaluate and return code.
        ob_start();
        eval( '?>' . $this->template_system->getSnippet() );
        $evaluated_code = ob_get_contents();
        ob_end_clean();
        return $evaluated_code;
    }
    
    /**
     * Method: setUnit()
     */
    public function setUnit( $unit )
    {
        $this->unit = $unit;
    }
    
    /**
     * Method: addData()
     */
    public function addData( $key, $value )
    {
        $this->data[$key] = $value;
    }
    
    
    // unit to be displayed
    protected $unit;
    
    // template system
    protected $template_system;
    
    // data
    protected $data;
}
